# -*- coding: utf-8 -*-
# @Time : 2021/7/3 14:08
# @Author : feimaotuiya
# @File : page_ecshop_back_remark_manage.py
# @Project : ecshop-gitee
import time
from selenium.webdriver.common.by import By


class PageEcshopBackRemarkManage():
    def __init__(self, driver):
        self.driver = driver
        # 元素定位
        self.loc_back_remark_manage_view_details = (By.XPATH, '//div[@id="listDiv"]/table[1]/tbody/tr[2]/td[8]/a[1]')
        self.loc_back_remark_manage_repy_remark = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[4]/td[2]/textarea')
        self.loc_back_remark_manage_submit = (By.NAME, 'submit')
        self.loc_back_remark_manage_reture_remark_lists = (By.XPATH, '/html/body/h1/span[1]/a')
        self.loc_back_remark_manage_delete_remark = (By.XPATH, '//div[@id="listDiv"]/table[1]/tbody/tr[2]/td[8]/a[2]')
        self.loc_back_remark_number = (By.XPATH, '//div[@id="listDiv"]/table[1]/tbody/tr[2]/td[1]')
        # 查看评论

    def back_remark_manage_view_details(self):
        self.driver.find_element(*self.loc_back_remark_manage_view_details).click()

        # 回复评论

    def back_remark_manage_repy_remark(self, word):
        self.driver.find_element(*self.loc_back_remark_manage_repy_remark).click()
        self.driver.find_element(*self.loc_back_remark_manage_repy_remark).send_keys(word)

        # 点击确定

    def back_remark_manage_submit(self):
        self.driver.find_element(*self.loc_back_remark_manage_submit).click()

        # 返回评论列表

    def back_remark_manage_reture_remark_lists(self):
        self.driver.find_element(*self.loc_back_remark_manage_reture_remark_lists).click()

        # 定位评论序号

    def back_remark_number_1(self):
        number_1 = self.driver.find_element(*self.loc_back_remark_number).text
        return number_1

        # 删除评论

    def back_remark_manage_delete_remark(self):
        self.driver.find_element(*self.loc_back_remark_manage_delete_remark).click()
        self.driver.switch_to.alert.accept()

        # 再次定位评论序号

    def back_remark_number_2(self):
        number_2 = self.driver.find_element(*self.loc_back_remark_number).text
        return number_2

    def back_remark_manage(self, word):
        self.back_remark_manage_view_details()
        self.back_remark_manage_repy_remark(word)
        self.back_remark_manage_submit()
        self.back_remark_manage_reture_remark_lists()
        time.sleep(1)
        number_1 = self.back_remark_number_1()
        self.back_remark_manage_delete_remark()
        time.sleep(1)
        number_2 = self.back_remark_number_2()
        return number_1, number_2
